from coin.exchange.base.kr_rest.product import NativeProduct, NormProduct
from coin.exchange.bithumb.kr_rest.currency import BithumbCurrency


class BithumbProduct(NativeProduct):
  _exchange = "Bithumb"
  NativeCurrencyType = BithumbCurrency

  def __init__(self, base, quote):
    NativeProduct.__init__(self, base, quote, base.native_currency)
    self.native_symbol_web = self.base.native_currency.upper()

  @classmethod
  def FromProduct(cls, product):
    assert isinstance(product, NormProduct), type(product)
    assert product.quote == "KRW"
    base = BithumbCurrency.FromCurrency(product.base)
    krw = BithumbCurrency.FromStrCurrency("KRW")
    return BithumbProduct(base, krw)

  @classmethod
  def FromStrProductImpl(cls, product, current_datetime):
    assert type(product) == str
    assert "-" in product
    ret = product.split("-")
    assert len(ret) == 2
    assert ret[0] != 'BCH', ret[0]
    base = BithumbCurrency.FromStrCurrency(ret[0])
    quote = BithumbCurrency.FromStrCurrency(ret[1])
    return BithumbProduct(base, quote)

  @classmethod
  def FromStrNativeProductImpl(cls, product, current_datetime):
    if '_' in product:
      base, quote = product.split('_')
      base = BithumbCurrency.FromStrNativeCurrency(base)
      quote = BithumbCurrency.FromStrNativeCurrency(quote)
    else:
      base = BithumbCurrency.FromStrNativeCurrency(product)
      quote = BithumbCurrency.FromStrCurrency("KRW")
    return BithumbProduct(base, quote)
